package com.qfedu.spring.springmvc.controller;

import com.qfedu.spring.springmvc.entity.User;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;

/**
 * @author zhang
 * @Title: commonValidateAdd
 * @date : 2022/5/3 12:11
 */
@RestController
@RequestMapping("/json")
public class JsonController {

    @RequestMapping(value = "/test1",produces = "text/html;charset=utf-8")
//    @ResponseBody
    public String test1(){
       // 如果我们自己在响应字符串中有中文会出现中文乱码的
        // springmvc 默认使用的字符串消息转换器编码是latin/iso-8859-1
        return "ok,你好";
    }

    @RequestMapping("/test2")
//    @ResponseBody
    public User test2(){
        User user = new User();
        user.setId(2);
        user.setName("kk");
        user.setAge(18);
        return user;

    }

    @RequestMapping("/test3")
//    @ResponseBody
    public List<User> test3(){
        User user = new User();
        user.setId(2);
        user.setName("kk");
        user.setAge(18);
        User user2 = new User();
        user2.setId(4);
        user2.setName("大壮");
        user2.setAge(20);
        return  Arrays.asList(user,user2);

    }
}
